// ignore: avoid_web_libraries_in_flutter

import 'package:flutter_app/ProductInfo.dart';
import 'package:flutter_app/pages/AppBarDemo.dart';
import 'package:flutter_app/pages/Product.dart';

import '../pages/Form.dart';
import '../pages/search.dart';
import 'package:flutter/material.dart';
import '../pages/Tabs.dart';
import '../pages/user/Login.dart';
import '../pages/user/RegisterFirst.dart';
import '../pages/user/RegisterSecond.dart';
import '../pages/user/RegisterThird.dart';
import '../pages/TabBarController.dart';
import '../pages/User.dart';
import '../pages/Button.dart';
import '../pages/Radio.dart';
import '../pages/HttpPage.dart';
import '../pages/GetPage.dart';
import '../pages/PostPage.dart';

//配置路由
final routes = {
  '/': (context, {arguments}) => Tabs(),
  '/form': (context) => Formpage(),
  '/search': (context, {arguments}) => Search(arguments: arguments),
  '/appBarDemo': (context) => AppBarDemoPage(),
  '/product': (context, {arguments}) => Productpage(
        arguments: arguments,
      ),
  '/productInfo': (context, {arguments}) => ProductInfo(arguments: arguments),
  '/login': (context) => LoginPage(),
  '/registerFirst': (context) => RegisterFirstPage(),
  '/registerSecond': (context) => RegisterSecondPage(),
  '/registerThird': (context) => RegisterThirdPage(),
  '/tabBarController': (context) => TabControllerPage(),
  '/user': (context) => UserPage(),
  '/button': (context) => ButtonPage(),
  '/radio': (context) => RadioPage(),
  '/http': (context) => HttpPage(),
  '/get': (context) => GetPage(),
  '/post': (context) => PostPage(),
};

//固定写法
var onGenerateRoute = (RouteSettings settings) {
  final String? name = settings.name;
  final Function pageContentBuilder = routes[name] as Function;
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(
          builder: (context) =>
              pageContentBuilder(context, arguments: settings.arguments));
      return route;
    } else {
      final Route route =
          MaterialPageRoute(builder: (context) => pageContentBuilder(context));
      return route;
    }
  }
};
